<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加数据</title>
	<!-- <script type="text/javascript" src="../js/jquery.min.js"></script>
	<script type="text/javascript"  src="../js/echarts.min.js"></script> -->
	<script type="text/javascript" src="js/jquery.min.js"></script>
	<script type="text/javascript" src="js/echarts.min.js"></script>
	<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        label {
            display: block;
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
    <div class="popup">
		<div class="popupCon">
			<h3 class="popupLabel"><span>*</span>时间</h3>
			<input type="text" id="date" data-options="{'type':'YYYY-MM-DD hh:mm','beginYear':2010,'endYear':2025}" required>
		</div> 
		<div class="popupCon popupAdd">
			<!-- <h3 class="popupLabel"><span>*</span>体重</h3>
			<input type="number" id="tizhong" required> -->
		</div>
	</div>
	
	<div class="bottom" onclick="submit()">
		<div class="submit">
			<div class="submitContent">提交</div>
		</div>
	</div>
</body>
<script type="text/javascript" src="js/jquery.date.js"></script>
    <script type="text/javascript">
    $.date('#date');
	let mbTypeId = '';
	let patientId = '';
	let editId = '';
	let editDate = '';
	let editNum = '';
	$(function(){
		getUrlParam();
		 
		
	});
	//url拆解
	function getQueryParams(url) {
		let params = {};
		let queryString = url ? url.split('?')[1] : window.location.search.slice(1);
		let arr = queryString.split('#')[0].split('&');
		
		for (let i = 0; i < arr.length; i++) {
			let a = arr[i].split('=');
			let paramName = a[0];
			let paramValue = typeof(a[1]) === 'undefined' ? true : decodeURIComponent(a[1].replace(/\+/g, ' '));
			
			if (params[paramName]) {
				if (Array.isArray(params[paramName])) {
					params[paramName].push(paramValue);
				} else {
					params[paramName] = [params[paramName], paramValue];
				}
			} else {
				params[paramName] = paramValue;
			}
		}
		return params;
	}
	function getUrlParam() {
		let url = window.location.href;
		let params = getQueryParams(url);
		name = params['name'];
		mbTypeId = params['mbTypeId'];
		patientId = params['patientId'];
		editId = params['editId'];
		editDate = params['date'];
		editNum = params['num'];
		console.log('11111editDate',editDate)
		if(editDate){
			document.getElementById("date").value = editDate
		}
		let ulHtml = ''
		if(mbTypeId == 10){
			ulHtml += '<h3 class="popupLabel"><span>*</span>体重（kg）</h3>'+
					'<input type="number" id="weight" required>'
		}
		if(mbTypeId == 3){
			ulHtml += '<h3 class="popupLabel"><span>*</span>糖化血红蛋白（HbA1c）</h3>'+
					'<input type="number" id="hba1c" required>'
		}
		if(mbTypeId == 4){
			ulHtml += '<h3 class="popupLabel"><span>*</span>甘油三酯（TG）</h3>'+
					'<input type="number" id="tg" required>'
		}
		if(mbTypeId == 5){
			ulHtml += '<h3 class="popupLabel"><span>*</span>总胆固醇（TC）</h3>'+
					'<input type="number" id="tc" required>'
		}
		if(mbTypeId == 6){
			ulHtml += '<h3 class="popupLabel"><span>*</span>高密度脂蛋白胆固醇（HDL - C）</h3>'+
					'<input type="number" id="hdlC" required>'
		}
		if(mbTypeId == 7){
			ulHtml += '<h3 class="popupLabel"><span>*</span>低密度脂蛋白胆固醇（LDL - C）</h3>'+
					'<input type="number" id="ldlC" required>'
		}
		if(mbTypeId == 8){
			ulHtml += '<h3 class="popupLabel"><span>*</span>血糖（mmol/L）</h3>'+
					'<input type="number" id="mmol" required>'+
					'<h3 class="popupLabel" style="margin-top:10px"><span>*</span>用餐时间</h3>'+
							'<select id="afterTime">'+
								'<option value="1">餐后1小时</option>'+
								'<option value="2">餐后2小时</option>'+
								'<option value="3">餐后3小时</option>'+
								'<option value="4">餐后4小时</option>'+
								'<option value="5">餐后5小时</option>'+
								'<option value="6">餐后6小时</option>'+
							'</select>'
		}
		if(mbTypeId == 9){
			ulHtml += '<h3 class="popupLabel"><span>*</span>收缩压（mmHg）</h3>'+
					'<input type="number" id="ssy" required>'+
					'<h3 class="popupLabel" style="margin-top:10px"><span>*</span>舒张压（mmHg）</h3>'+
							'<input type="number" id="szy" required>'
		}
		$(".popupAdd").append(ulHtml);
		
		document.getElementById("weight").value = editNum
	}
	//提交数据
	function submit(){
		let form ={
			measureTime:"",
			time:"",
			hba1c:"",
			tg:"",
			tc:"",
			mmol:"",
			hdlC:"",
			ldlC:"",
			afterTime:"",
			ssy:"",
			szy:"",
			weight:"",
			patientId:patientId,
			mbTypeId:mbTypeId,
			id:editId
		}
		
		let date = document.getElementById("date").value;
		var str = "Hello World";
		form.measureTime = date.substr(0, 10);
		form.time = date.substr(11, 16);
		if(date == ""){
			alert("请选择日期");
				return false;
		}else{
			if(mbTypeId == 10){
				form.weight = document.getElementById("weight").value;
				if(form.weight == ""){
					alert("请填写体重");
					return false;
				}else{
					submitDate(form);
				}
			}else if(mbTypeId == 3){
				form.hba1c = document.getElementById("hba1c").value;
				if(form.hba1c == ""){
					alert("请填写糖化血红蛋白");
					return false;
				}else{
					submitDate(form);
				}
			}else if(mbTypeId == 4){
				form.tg = document.getElementById("tg").value;
				if(form.tg == ""){
					alert("请填写甘油三酯");
					return false;
				}else{
					submitDate(form);
				}
			}else if(mbTypeId == 5){
				form.tc = document.getElementById("tc").value;
				if(form.tc == ""){
					alert("请填写总胆固醇");
					return false;
				}else{
					submitDate(form);
				}
			}else if(mbTypeId == 6){
				form.hdlC = document.getElementById("hdlC").value;
				if(form.hdlC == ""){
					alert("请填写高密度脂蛋白胆固醇");
					return false;
				}else{
					submitDate(form);
				}
			}else if(mbTypeId == 7){
				form.ldlC = document.getElementById("ldlC").value;
				if(form.ldlC == ""){
					alert("请填写低密度脂蛋白胆固醇");
					return false;
				}else{
					submitDate(form);
				}
			}else if(mbTypeId == 8){
				form.mmol = document.getElementById("mmol").value;
				form.afterTime = document.getElementById("afterTime").value;
				if(form.mmol == ""){
					alert("请填写血糖");
					return false;
				}else if(form.afterTime == ""){
					alert("请选择用餐时间");
					return false;
				}else{
					submitDate(form);
				}
			}else if(mbTypeId == 9){
				form.ssy = document.getElementById("ssy").value;
				form.szy = document.getElementById("szy").value;
				if(form.ssy == ""){
					alert("请填写收缩压");
					return false;
				}else if(form.szy == ""){
					alert("请填写舒张压");
					return false;
				}else{
					submitDate(form);
				}
			}
		}	
		
	}
	function submitDate(form){
		// 判断是编辑还是新增
		if(form.id == "" || form.id == undefined || form.id == null){
			$.ajax({
				url: 'https://weixintest.api.dyzh120.com/api/v1/mbData/add',
				contentType: 'application/json; charset=utf-8',
				type:'post',
				data:JSON.stringify(form),
				success: function(response) {
					if(response.result.code == "200"){
						window.history.back();
					}else{
						alert("修改失败");
					}
				}
			})
		}else{
			$.ajax({
				url: 'https://weixintest.api.dyzh120.com/api/v1/mbData/edit',
				contentType: 'application/json; charset=utf-8',
				type:'post',
				data:JSON.stringify(form),
				success: function(response) {
					if(response.result.code == "200"){
						window.history.back();
					}else{
						alert("修改失败");
					}
				}
			})
			
		}
		
	}
    </script>
	<style>
		.popup{
		}
		.popupCon {
		    width: 100%;
			margin-bottom:20px;
		}
		.popupLabel {
		    font-family: PingFang SC,PingFang SC;
		    font-weight: 400;
		    font-size:16px;
		    color: #323233;
			display: flex;
		}
		.popupLabel span {
		    width:16px;
		    height:30px;
		    color: #fc2249;
		    font-size:24px;
		    display: inline-block;
		}
		.popupCon input,.popupCon select{
		    width:98%;
		    height:40px;
		    line-height: 40px;
		    background: #FFFFFF;
		    border-radius:4px;
		    border:1px solid #DCDEE0;
		    text-align: left;
		    padding-left:10px;
		    font-family: PingFang SC,PingFang SC;
		    font-weight: 400;
		    font-size:16px;
		    color: #323233;
		}
		.popupCon option{
		    width:98%;
		    height:40px;
		    line-height: 40px;
		    background: #FFFFFF;
		    font-family: PingFang SC,PingFang SC;
		    font-weight: 400;
		    font-size:16px;
		    color: #323233;
		}
		
		.bottom{
			width:100%;
			height:40px;
			position: fixed;
			left: 0;
			bottom:50px;
			right: 0;
			z-index: 100;
		}
		.submit {
			background-color: #FFFFFF;
			display: flex;
			justify-content: center;
			align-items: center;
			text-align: center;
			margin:0 auto;
			padding: 20px
		}
		.submitContent {
			background-color: #1971FF;
			display: flex;
			height: 40px;
			width: 100%;
			font-size:16px;
			font-family: PingFangSC, PingFang SC;
			font-weight: 600;
			color: #FFFFFF;
			line-height:40px;
			justify-content: center;
			align-items: center;
			border-radius:5px;
			text-align: center;
		}
		
		
		
		
		body{
		  font-family:PingFangSC-Regular;
		}
		a {
		  text-decoration: none;
		}
		*{
			margin: 0;
			padding:0;
		}
		ol,li {
		  margin: 0;
		  padding: 0
		}
		
		li {
		  list-style-type: none
		}
		
		#date-wrapper {
		  position: fixed;
		  bottom: 0;
		  left: 50%;
		  width: 100%;
		  margin: -139px 0 0 -50%;
		  z-index: 9999;
		  text-align: center;
		  background: #fff;
		  border-radius: 3px;
		  padding-bottom: 10px;
		  display: none
		}
		
		#d-mask {
		  position: fixed;
		  width: 100%;
		  height: 100%;
		  top: 0;
		  left: 0;
		  background: #000;
		  filter: alpha(Opacity=50);
		  -moz-opacity: .5;
		  opacity: .5;
		  z-index: 55;
		  display: none
		}
		
		#date-wrapper h3 {
		  font-family:PingFangSC-Regular;
		  line-height: 50px;
		  color: #333333;
		  font-size: 15px;
		  margin: 0;
		  border-radius: 3px 3px 0 0
		}
		
		#date-wrapper ol,#d-tit>div {
		  width: 20%;
		  float: left;
		  position: relative
		}
		
		#d-content {
		  padding: 10px;
		  border: 1px solid #E5E5E5;
		}
		
		#d-content #d-bg {
		  height: 120px;
		  overflow: hidden;
		  margin-bottom: 10px;
		  position: relative;
		  border: 1px solid #ddd;
		}
		
		#d-cancel,#d-confirm {
		  border-radius: 3px;
		  float: left;
		  width: 40%;
		  line-height: 30px;
		  font-size: 15px;
		  color: #333333;
		  margin: 0 5%;
		  padding-top: 10px;
		}
		
		#d-confirm {
		  color: #5CBB9D;
		}
		
		#date-wrapper li {
		  line-height: 40px;
		  height: 40px;
		  cursor: pointer;
		  position: relative
		}
		
		#d-tit {
		  overflow: hidden;
		  line-height: 30px;
		  margin-bottom: -1px
		}
		
		#date-wrapper ol {
		  -webkit-overflow-scrolling: touch;
		  position: absolute;
		  top: 0;
		  left: 0
		}
		
		#date-wrapper ol:nth-child(2) {
		  left: 20%;
		}
		
		#date-wrapper ol:nth-child(3) {
		  left: 40%;
		}
		
		#date-wrapper ol:nth-child(4) {
		  left: 60%;
		}
		
		#date-wrapper ol:nth-child(5) {
		  left: 80%;
		}
		
		#date-wrapper ol:nth-child(6) {
		  left: 100%;
		}
		
		
		#d-content #d-bg:after{
		    content: '';
		    height: 40px;
		    background: #F3F3F3;
		    position: absolute;
		    top: 40px;
		    left: 0;
		    width: 100%;
		    z-index: -1;
		}
		
	</style>
</body>
</html>
